<template>
  <el-dialog :close-on-click-modal="false" v-model="visible" title="查看密钥" @close="resetForm" width="40%">
    <el-form v-loading="editLoading" ref="formRef" :model="formData" :rules="formRules" label-width="120px">
      <div class="px-4">
        <el-form-item prop="clientId" label="应用ID">
          <label>{{ formData.clientId }}</label>
        </el-form-item>
        <el-form-item prop="clientSecret" label="应用密钥">
          <label>{{ formData.clientSecret }}</label>
        </el-form-item>
      </div>
    </el-form>
  </el-dialog>
</template>
<script setup>
import { getSecret } from '@/api/system/app'
import { ElMessage, ElMessageBox } from 'element-plus'

const props = defineProps({
  id: {
    type: String,
    default: ''
  },
  visible: {
    type: Boolean,
    default: false
  }
})
const emit = defineEmits(['update:visible', 'create', 'update'])
const formRef = ref(null)
const formData = reactive({
  clientId: '',
  clientSecret: '',
})
const formRules = reactive({})
const resetForm = () => {
  delete formData.id
  emit('update:visible')
  formRef.value.resetFields()
}
const submitBtnLoading = ref(false)
const editLoading = ref(false)
watch(
  () => props.visible,
  async (newValue, oldValue) => {
    if (newValue) {
      submitBtnLoading.value = false
      const { id } = props
      if (id) {
        editLoading.value = true
        const { data } = await getSecret(id)
        Object.assign(formData, data)
        editLoading.value = false
      }
    }
  }
)
</script>
<style lang="scss" scoped></style>
